package com.jiantong.user.impl.service;

import com.google.common.base.Throwables;
import com.jiantong.user.impl.dao.FeedBacksDao;
import com.jiantong.user.model.FeedBacks;
import com.jiantong.user.service.FeedBacksReadService;
import io.terminus.boot.rpc.common.annotation.RpcProvider;
import io.terminus.common.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 意见反馈
 * Created by mz03 on 2017/3/23.
 * zyp
 */
@Slf4j
@Service
@RpcProvider
public class FeedBacksReadServiceImpl implements FeedBacksReadService{

    private final FeedBacksDao feedBacksDao;
    @Autowired
    public FeedBacksReadServiceImpl(FeedBacksDao feedBacksDao){
        this.feedBacksDao = feedBacksDao;
    }

    /**
     * 根据ID查询
     *
     * @param id 主键id
     * @return FeedBacks 对象
     */
    @Override
    public Response<FeedBacks> findById(Long id) {
        try {
            FeedBacks feedBacks = feedBacksDao.findById(id);
            if (feedBacks != null){
                return Response.ok(feedBacks);
            }else {
                log.error("feedBacks (id={}) is not found", id);
                return Response.fail("breedReport.not.found");
            }
        } catch (Exception e){
            log.error("failed to find feedBacks(id={}), cause:{}", id, Throwables.getStackTraceAsString(e));
            return Response.fail("feedBacks.find.fail");
        }


    }
}
